package schedule

import (
	"yuanchang/spider/http"
	"yuanchang/spider/schedule/support"
	"yuanchang/spider/util/store"
)

type ScheduleInterface interface {
	PushRequest(r *http.Request)
	PopRequest() *http.Request
}

// make schedule by name
func MakeSchedule(name string) ScheduleInterface {
	switch name {
	case "chan":
		return NewChanSchedule()
	case "redis":
		return NewRedisSchedule()
	default:
		return nil
	}
}

func NewChanSchedule() *support.ChanSchedule {
	schedule := new(support.ChanSchedule)
	schedule.RequestChan = make(chan *http.Request)
	return schedule
}

func NewRedisSchedule() *support.RedisSchedule {
	schedule := new(support.RedisSchedule)
	schedule.Storage = store.MakeStore("redis")
	return schedule
}
